<template>
    <div>
        <div class="title">当地热销美食推荐</div>
        <ul>

            <li
                    class="item border-bottom"
                    v-for="(item,key) of food"
                    :data-id="item.food_id"
                    @click="reflesh"
                    v-show="key<num"
            >

                <img
                            class="item-img"
                            :src="item.food_picture"
                    >
                <div class="item-info">
                  <router-link :to="{name: '/Fooddetail', params:{id:item.food_id}}">
                    <p class="item-title">{{item.food_title}}</p>
                    <p class="item-desc">{{item.food_content}}</p>
                    <button class="item-button">查看详情</button>
                  </router-link>
                </div>
            </li>
        </ul>
        <span @click="showMore">{{txt}}</span>
    </div>
</template>

<script>
    import axios from 'axios'
export default {
    name: "HomeRecommend",
    props: ['fooding'],
    data () {
        return {
            food: [],
            food_id: '',
            food_picture: '',
            food_title: '' ,
            food_content: '',
            food_userid: '',
            food_userimage: '',
            food_time: '',
            isShow: true,
            txt: '显示全部',
            num: 3
        }
    },
    mounted(){
        axios.get('/api/food/index.html')
            .then((res) => {
                console.log(res);
                this.food = res.data.data.data;
            })
            .catch((err) => {
                console.log(err);
            });
    },
    methods: {
        reflesh(){
            location.reload()
        },
        showMore(){

            this.isShow = !this.isShow;

            this.num = this.isShow? 2: this.food.length;
            this.txt = this.isShow?  '显示全部':'收起'
        }

    }
}
</script>

<style lang="stylus" scoped>
@import '~styles/mixins.styl'
.title
    margin-top 0
    line-height .8rem
    background #eee
    text-indent .2rem
.item
    overflow hidden
    display flex
    height 1.9rem
    .item-img
        width 1.7rem
        height 1.7rem
        padding .1rem
    .item-info
        flex 1
        padding .1rem
        min-width 0
        .item-title
            line-height .54rem
            font-size .32rem
            ellipsis()
        .item-desc
            line-height .4rem
            color #ccc
            ellipsis()
        .item-button
            line-height .44rem
            margin-top .16rem
            background #ff9300
            padding 0 .1rem
            border-radius .06rem
            color #fff
</style>
